package myapps.ttclient.connection;

import java.io.IOException;

import myapps.ttclient.activity.connection.ConnectionEditActivity_Bluetooth;
import myapps.ttclient.activity.connection.ConnectionEditActivity;
import myapps.ttclient.app.TTClientApplication;
import myapps.ttclient.baseclass_and_interface.TTClientConnection;
import myapps.ttclient.protocol.PhoneClientConnectionBluetooth;


import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Connection_Bluetooth extends Connection
{
	private String address;
	
	public Connection_Bluetooth()
	{
		super();
		
		this.address = "";
	}
	
	public static Connection_Bluetooth load(SharedPreferences preferences, int position)
	{
		Connection_Bluetooth connection = new Connection_Bluetooth();
		
		connection.name = preferences.getString("connection_bluetooth_" + position + "_address", null);
		connection.address = preferences.getString("connection_bluetooth_" + position + "_address", null);
		
		return connection;
	}
	
	@Override
	public void save(Editor editor, int position)
	{
		editor.putString("connection_bluetooth_" + position + "_name", this.name);
		editor.putString("connection_bluetooth_" + position + "_address", this.address);
	}
	
	@Override
	public void edit(Context context)
	{
		Intent intent = new Intent(context, ConnectionEditActivity_Bluetooth.class);
		
		intent.putExtra("name", this.name);
		intent.putExtra("address", this.address);
		
		intent.putExtra("type", "edit");
		
		ConnectionEditActivity.connectionParam = this;
		
		context.startActivity(intent);
	}
	
	@Override
	public TTClientConnection connect(TTClientApplication application) throws IOException
	{
		return PhoneClientConnectionBluetooth.create(application, this.address);
	}
	
	public String getAddress()
	{
		return address;
	}
	
	public void setAddress(String address)
	{
		this.address = address;
	}
}
